<template>
  <el-container style="height: 100%;  solid #eee" class="home-container">
    <el-header>
      <div>
        <img src="../assets/logo.png" alt="" />
      </div>
      <span>校园运动健康平台</span>
      <div>
        <el-dropdown class="userInfo" @command="commandHandler">
          <span class="el-dropdown-link">
            {{ user.name }}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="PersonalCenter"
              >个人中心</el-dropdown-item
            >
            <el-dropdown-item command="logout">登出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>

    <el-container>
      <el-aside width="200px">
        <el-menu
          router
          default-active="2"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-menu-item index="Carousel">
            <i class="el-icon-s-home"></i>
            <span slot="title">Dashboard</span>
          </el-menu-item>
          <template v-if="user.id.length == 12">
            <el-menu-item index="BMI">
              <i class="el-icon-s-home"></i>
              <span slot="title">BMI检测</span>
            </el-menu-item>
            <el-menu-item index="classMessage">
              <i class="el-icon-s-home"></i>
              <span slot="title">所在班级信息</span>
            </el-menu-item>
            <el-menu-item index="PersonalCenter">
              <i class="el-icon-s-home"></i>
              <span slot="title">个人中心</span>
            </el-menu-item>
          </template>
          <template v-if="user.id.length == 7">
            <el-menu-item index="studentManage"
              ><i class="el-icon-user"></i>学生信息总表</el-menu-item
            >
            <el-menu-item index="studentSeach"
              ><i class="el-icon-user-solid"></i>学生信息查询</el-menu-item
            >

            <el-menu-item index="studentColumn"
              ><i class="el-icon-basketball"></i>本学期跑步公里数</el-menu-item
            >
            <el-menu-item index="studentDualAxes"
              ><i class="el-icon-grape"></i>第一学年统计</el-menu-item
            >
            <el-menu-item index="studentBar"
              ><i class="el-icon-football"></i>第二学年统计</el-menu-item
            >
            <el-menu-item index="studentPoint"
              ><i class="el-icon-user-solid"></i>身高体重比率</el-menu-item
            >
            <el-menu-item index="studentPie"
              ><i class="el-icon-user-solid"></i>各学期跑步汇总</el-menu-item
            >
            <el-menu-item index="addStudent"
              ><i class="el-icon-user-solid"></i>添加学生信息</el-menu-item
            >
            <el-menu-item index="classManagement"
              ><i class="el-icon-user-solid"></i>班级管理</el-menu-item
            >
            <el-menu-item index="TeacherCenter">
              <i class="el-icon-s-home"></i>
              <span slot="title">个人中心</span>
            </el-menu-item>
          </template>
          <template v-if="user.id.length != 7 && user.id.length != 12">
            <el-submenu index="1">
              <template slot="title"
                ><i class="el-icon-user-solid"></i>Student</template
              >
              <el-menu-item-group>
                <el-menu-item index="studentSeach"
                ><i class="el-icon-user"></i>学生信息查询</el-menu-item
                >
                <el-menu-item index="addStudent"
                  ><i class="el-icon-user-solid"></i>添加学生信息</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
            <el-submenu index="2">
              <template slot="title"
                ><i class="el-icon-user-solid"></i>Teacher</template
              >
              <el-menu-item-group>
                <el-menu-item index="wx"
                  ><i class="el-icon-user-solid"></i>教师信息</el-menu-item
                >
                <el-menu-item index="distribution"
                  ><i class="el-icon-user-solid"></i>教师分布</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>

            <el-menu-item index="Peoplemessage"
              ><i class="el-icon-user-solid"></i>人员信息调度</el-menu-item
            >
            <el-menu-item index="addTeacher"
              ><i class="el-icon-user-solid"></i>添加老师信息</el-menu-item
            >
            <el-menu-item index="AdminCenter">
              <i class="el-icon-s-home"></i>
              <span slot="title">个人中心</span>
            </el-menu-item>
          </template>
          <el-menu-item index="chatroom">
            <i class="el-icon-chat-dot-round"></i>
            <span slot="title">运动聊天室</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      user: JSON.parse(window.sessionStorage.getItem("user")),
    };
  },
  methods: {
    commandHandler(command) {
      if (command == "logout") {
        this.postRequest("/logout");
        window.sessionStorage.removeItem("tokenStr");
        window.sessionStorage.removeItem("user");
        this.$router.replace("/");
      }
      if (command == "PersonalCenter") {
        if (this.user.id.length == 12) {
          this.$router.replace("/PersonalCenter");
        } else if (this.user.id.length == 7) {
          this.$router.replace("/TeacherCenter");
        } else {
          this.$router.replace("/AdminCenter");
        }
      }
    },
  },
};
</script>

<style>
.home-container {
}
.el-header {
  background-color: #707883;
  color: rgb(255, 255, 255);
  display: flex;
  align-items: center;
  font-size: 30px;
}
.el-aside {
  background-color: #545c64;
  line-height: 200px;
  height: 100%;
}
.home-container .userinfo {
  cursor: pointer;
  margin-left: 50%;
}
.el-dropdown-link {
  width: 48px;
  height: 48px;
  border-radius: 24px;
  float: inline-start;
}
</style>
